package practicalWork;

import java.util.ArrayList;
import java.util.List;

import exception.NoEsNotaValidaException;
import subjectAndProfessorship.EnrolledInProfessorship;
import subjectAndProfessorship.Professorship;
import util.MyDate;

/**
 * autor:Medici Maria Laura
 */
public class InGroup extends ToHandIn{
	/* ******************************** Variables ******************************** */
	private List<EnrolledInProfessorship>  students = new ArrayList<EnrolledInProfessorship>();

	/* ******************************* Constructor ******************************* */
	public InGroup(MyDate date) {
		super(date);	
	}
	
	/* ******************************** Get & Set ******************************** */
	public void setStudents(List<EnrolledInProfessorship> students) {
		this.students = students;
	}
	
	public List<EnrolledInProfessorship> getStudents() {
		return students;
	}

	/* ********************************* Metodos ********************************* */
	/**
	 * Elije del grupo de alumnos el representante con menor apellido 
	 */
	public String apellido() {
		String menorApe = (this.getStudents().remove(0)).apellidoAlumno();
		for(EnrolledInProfessorship student : this.getStudents()){
			if(student.apellidoAlumno().compareTo(menorApe) < 0){
				menorApe = student.nombreAlumno();
			}
		}
		return menorApe;
	}

	/**
	 * se fija si un alumno forma parte de un grupo de una misma entrega
	 */
	public boolean perteneceAlumno(EnrolledInProfessorship alumno) {
		boolean esta = false;
		for(EnrolledInProfessorship student :this.getStudents()){
			if(student == alumno){
				esta = true;
			}
		}
		return esta;
	}

	/**
	 * Devuelve un representante de la entrega , con el menor apellido
	 */
	public EnrolledInProfessorship takeAlumnoRepresentante() {
		//
		EnrolledInProfessorship menorApe = (this.getStudents().remove(0));
		for(EnrolledInProfessorship student : this.getStudents()){
			if(student.apellidoAlumno().compareTo(menorApe.apellidoAlumno()) < 0){
				menorApe = student;
			}
		}
		return menorApe;
	}

	/**
	 * Devuelve los alumnos de una entrega
	 */
	public List<EnrolledInProfessorship> makeListAlumno() {
		return this.getStudents();
	}
	
	/**
	 * Agrega una nota a todos los alumnos de una entrega
	 */
	public void agregarNotaAAlumno(int nota) {
		for(EnrolledInProfessorship alum :this.getStudents()){
	
				try {
					alum.agregarNota(nota);
				} catch (NoEsNotaValidaException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			
		}
	}
	
	/**
	 * Agrega un alumno  a la entrega
	 * @param student
	 */
	public void agregarAlumno( EnrolledInProfessorship student){
		this.getStudents().add(student);
	}
	
	/**
	 * Saca a un alumno de una entrega debidoa  que no puede rendir el trabajo practico por su regularidad actual
	 */
	public void removerAlumnos(Professorship catedra) {
		for(EnrolledInProfessorship alum :this.getStudents()){
			if(! alum.miRegularidad().rendirTp()){
				this.removerAlumno(alum);
			}
		}
		
	}

	/**
	 * saca al alumno de una entrega
	 * @param alum
	 */
	private void removerAlumno(EnrolledInProfessorship alum) {
		this.getStudents().remove(alum);
	}
/**
 * Dice si una entrega no tiene alumnos
 */
	public boolean vacia() {
		
		return this.getStudents().isEmpty();
	}
}
